var dgram = require('dgram');
var http = require('http');
var util = require('util');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

Device = new Schema({
	hwAddress : {
		type : String,
		unique : true
	},
	inetAddress : String,
	name : {
		type : String,
		unique : true
	},
	status : {
		type : String,
		index : true,
		enum : [ 'online', 'offline', 'noconf' ],
		'default' : 'noconf'
	},
	location : String,
	description : String,
	ports : [ {
		type : mongoose.Schema.ObjectId,
		ref : 'Port'
	} ]
});

Device.pre('remove', function(next, done) {
	this.ports.forEach(function(port) {
		PortModel.remove({ _id : port }, next);
	});
});

DeviceModel = mongoose.model('Device', Device);
